import { createStore, Store, useStore as useVuexStore } from 'vuex'
import type { IRootState, IStoreType } from './type'

import login from './login/login'

const store = createStore<IRootState>({
  state: () => {
    return {}
  },
  mutations: {},
  actions: {},
  modules: {
    login
  }
})
// 调用数据持久化函数-> 页面刷新后，在main.ts中执行一次
export function setupStore() {
  store.dispatch('login/loadLocalLogin')
}

// 定义包含vuex和自定义模块的交叉类型
export function useStore(): Store<IStoreType> {
  return useVuexStore()
}
export default store
